﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZX.WebApp.Crm
{
    public partial class V_DatSysNewsInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["ID"];
            string choose = Request.QueryString["choose"].ToString();

            #region 访问数据库代码
            //打开数据库
            string connString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ToString();
            try
            {
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
                {
                    conn.Open();
                    //拼接sql语句
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    if (choose == "de")    //查询发件箱的短信内容【已发信息的内容】
                    {
                        sb.Append("select createPeopleName,title,content,createDate ");
                        sb.Append("from DatSysNews ");
                        sb.Append("where ID = @ID and ISDelete = 0;");
                    }
                    else if (choose == "i")//查询收件箱、未读信息的短信内容【收到信息的内容】
                    {
                        sb.Append("update DatSysNewsInfo set ReadDate = GETDATE() where ID=@ID;");
                        sb.Append("select d.createPeopleName,d.title,d.content,d.createDate ");
                        sb.Append("from DatSysNewsInfo i left join DatSysNews d on i.nid = d.id ");
                        sb.Append("where i.ID =@ID and i.ISDelete=0;");
                    }

                    System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand(sb.ToString(), conn);
                    com.Parameters.Add("ID", System.Data.SqlDbType.UniqueIdentifier);
                    com.Parameters["ID"].Value = Guid.Parse(id);

                    //接收数据
                    System.Data.SqlClient.SqlDataReader dr = com.ExecuteReader();
                    while (dr.Read())
                    {
                        txtTitle.InnerText = dr["title"].ToString();
                        txtCreateName.Text = dr["createPeopleName"].ToString();
                        txtTime.Text = dr["createDate"].ToString();
                        txtContent.InnerText = dr["content"].ToString();
                    }
                    dr.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            #endregion
        }
    }
}